package com.example.hms.awareness;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;

import com.huawei.hms.kit.awareness.barrier.BarrierStatus;

import java.util.Map;

import static com.example.hms.awareness.BarrierUtil.*;

public class TimeBarrierReceiver extends BroadcastReceiver {
    
    private static final String TAG = TimeBarrierReceiver.class.getSimpleName();
    
    @Override
    public void onReceive(Context context, Intent intent) {
        BarrierStatus barrierStatus = BarrierStatus.extract(intent);
        String label = barrierStatus.getBarrierLabel();

        int barrierPresentStatus = barrierStatus.getPresentStatus();
        switch (label) {
            case "3D Time barrier":
                if (barrierPresentStatus == BarrierStatus.TRUE) {

                Log.d(TAG, label + " status:true");


                Intent intent1= context.getPackageManager().getLaunchIntentForPackage("com.huawei.hms.modeling3d.model");
                intent1.setPackage(null); // 加上这句代码
                context.startActivity(intent1);
                }else if(barrierPresentStatus == BarrierStatus.FALSE) {
                    Log.i(TAG, label + " status:false");
                }else if(barrierPresentStatus ==BarrierStatus.UNKNOWN) {
                    Log.i(TAG, label + " status:unknown");}
                        break;
            case "study Time barrier":
                if (barrierPresentStatus == BarrierStatus.TRUE) {

                    Log.d(TAG, label + " status:true");
//                    Intent intent2 = new Intent();
//                    intent2.setComponent(new ComponentName("com.tencent.mm","com.tencent.mm.ui.LauncherUI"));
//                    context.startActivity(intent2);

                    Intent intent0 = context.getPackageManager().getLaunchIntentForPackage("cn.xuexi.android");
                    intent0.setPackage(null); // 加上这句代码
                    context.startActivity(intent0);}
                else if(barrierPresentStatus == BarrierStatus.FALSE) {
                    Log.i(TAG, label + " status:false");
                }else if(barrierPresentStatus ==BarrierStatus.UNKNOWN) {
                    Log.i(TAG, label + " status:unknown");}

                break;
            case "we chat":
                if (barrierPresentStatus == BarrierStatus.TRUE) {

                    Log.d(TAG, label + " status:true");

                    Intent intent2= context.getPackageManager().getLaunchIntentForPackage("com.tencent.mm");
                    intent2.setPackage(null); // 加上这句代码
                    context.startActivity(intent2);
                }else if(barrierPresentStatus == BarrierStatus.FALSE) {
                    Log.i(TAG, label + " status:false");
                }else if(barrierPresentStatus ==BarrierStatus.UNKNOWN) {
                    Log.i(TAG, label + " status:unknown");}
                break;


        }
    }
}
